<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use app\common\model\Order;
use think\Db;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {

    	$totalUser = Db::name('user')->count();
    	$totalOrder = Db::name('order')->where(['status' => ['in', [Order::STATUS_SIGN, Order::STATUS_SUCCESS]]])->count();
    	$totalAgent = Db::name('agentShop')->where(['status' => \app\common\model\AgentShop::STATUS_Y])->count();
    	$totalPromoter = Db::name('promotion')->where(['status' => \app\common\model\Promotion::STATUS_Y])->count();
    	$totalMoney = Db::name('user')->sum('money');
    	$totalStock = Db::name('agentStock')->sum('number');
    	$this->assign([
    		'totalUser' => $totalUser,
		    'totalOrder' => $totalOrder,
		    'totalAgent' => $totalAgent,
		    'totalPromoter' => $totalPromoter,
		    'totalMoney' => $totalMoney,
		    'totalStock' => $totalStock
	    ]);
        return $this->view->fetch();
    }

}
